930B - Game with String - CodeForces Solution


implementation probabilities strings *1600

Please click on ads to support us..

C++ Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define dec double 
#define ll long long
using namespace std;
const int MAXN = 5005;

int n; char s[MAXN][MAXN];

// 第一个位置是什么、第几位、有几个 
int cnt[26][MAXN][26], num[26]; dec ans;

int main() {
	scanf("%s", s[0] + 1); n = strlen(s[0] + 1);
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < n; j++) {
			s[i][j] = s[i - 1][j + 1];
		}
		s[i][n] = s[i - 1][1];
	}
	
	for (int i = 0; i < n; i++) {
		num[s[i][1] - 'a'] ++;
		for (int j = 2; j <= n; j++) {
			cnt[s[i][1] - 'a'][j][s[i][j] - 'a'] ++;
		}
	}
	for (int i = 0, mx, tmp; i < 26; i++) {
		if (!num[i]) continue;
		mx = 0;
		for (int j = 2; j <= n; j++) {
			tmp = 0;
			for (int k = 0; k < 26; k++) {
				if (cnt[i][j][k] == 1) tmp ++;
			}
			mx = max(mx, tmp);
		}
		ans += (dec)mx / n;
	}
	printf("%.15lf", ans);
	return 0;
}
		   				 			 	    				  	 	  	


Comments

Submit
0 Comments
More Questions

768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains
664A - Complicated GCD
1635D - Infinite Set
1462A - Favorite Sequence
1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square
766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal